package com.feicheng.controller.shop.admin.system;


import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Order;
import com.feicheng.service.IFHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController("/shop/admin/home")
@RequestMapping("/shop/admin/home")
public class HomeController {

    @Autowired
    IFHomeService ifHomeService;

    /**
     * 取得某一时段的进店人数
     * @return
     */

    @GetMapping("/order_count")
    public ResultInfo getOrderCounts(Order order, @RequestParam(defaultValue = "Y") String part) {
        return ifHomeService.getOrderCount(order.getStoreId(), order.getSt(), order.getEt(), part);
    }

    @GetMapping("/all")
    public ResultInfo getAll(Order order, @RequestParam(defaultValue = "Y") String part) {
        JSONObject result = new JSONObject();

        ResultInfo orderCountResult = ifHomeService.getOrderCount(order.getStoreId(), order.getSt(), order.getEt(), part);
        result.put("orderCount", orderCountResult.get(Constant.RESULT.DATA));

        ResultInfo cardAmountResult = ifHomeService.getCardAmount(order.getStoreId(), order.getSt(), order.getEt(), part);
        result.put("cardAmount", cardAmountResult.get(Constant.RESULT.DATA));

        ResultInfo calculateTimeResult = ifHomeService.calculateTimeMoney(order.getStoreId(), order.getSt(), order.getEt(), part);
        result.put("calculateTime", calculateTimeResult.get(Constant.RESULT.DATA));

        ResultInfo depositRecordResult = ifHomeService.getDepositAmount(order.getStoreId(), order.getSt(), order.getEt(), part);
        result.put("depositRecord", depositRecordResult.get(Constant.RESULT.DATA));

        ResultInfo depositBackRecordResult = ifHomeService.getDepositBackAmount(order.getStoreId(), order.getSt(), order.getEt(), part);
        result.put("depositBackRecord", depositBackRecordResult.get(Constant.RESULT.DATA));

        return ResultInfo.success(result);
    }
}
